//
// Created by Jisam on 2024/8/9 22:32.
// solve 202312-2
#include <bits/stdc++.h>

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

using namespace std;


void solve() {
    int n;
    cin >> n;

    while (n--){
        i64 res = 1,a= 0;
        int b = 0;
        cin >> a  >> b;
        for(int i = 2; i <= a / i ; i ++)
        {
            int cnt = 0;
            while(a % i == 0)
            {
                a /= i ;
                cnt ++;
            }
            if(cnt >= b) res *= pow(i,cnt);
        }
        cout << res <<"\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
//    cin >> T;
    while (T--) solve();
//    cout << "\n"[];
    return 0;
}